/**
 * XGeneratorFrame.java
 * 2012-2-20 下午10:19:12
 */
package xgenerator.ui.swing;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import xgenerator.ui.swing.adapter.LookAndFeelAdapter;
import xgenerator.ui.swing.adapter.MenuAdapter;
import xgenerator.util.HttpClient;

/**
 * <p>
 * Title:类的中文名
 * </p>
 * <p>
 * Description:具体功能见各方法描述
 * </p>
 * <p>
 * Copyright:Copyright (c) 2012
 * </p>
 * 
 * @author <a href="mailto:lishushan@gmail.com">liss</a>
 * @version 1.0
 */
public class XGeneratorFrame extends JFrame implements UIConstants {
	
	private ActionListener menuAction = new MenuAdapter(this);
	
	private boolean isFullScreen = false;

	private JLabel logoLabel;
	private JToolBar toolBar;
	private JPanel homePanel;
	private JPanel statusBar;
	
	/**
	 * constructor
	 */
	public XGeneratorFrame() {
		super();
		initComponents();
		setFaceFeature();
	}

	/**
	 * <p>
	 * Title：初始化组件
	 * </p>
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 */
	private void initComponents() {
		this.setJMenuBar(buildJMenuBar());
		this.setContentPane(buildContentPane());
		
		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				super.windowClosing(e);
				System.exit(0);
			}
		});
	}
	
	/**
	 * <p>
	 * Title：设置显示特性
	 * </p>
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 */
	private void setFaceFeature() {
		this.setTitle("XGenerator");
		this.setIconImage(IconUtils.createIconImage(APP_ICON_IMAGE));

		Toolkit tk = Toolkit.getDefaultToolkit();
		Dimension screenSize = tk.getScreenSize();
		int screenHeight = screenSize.height;
		int screenWidth = screenSize.width;
//		this.setSize(screenWidth, screenHeight - 30);
//		this.setSize((int)(screenWidth*0.618), (int)(screenHeight*0.618));
		this.setSize(850, 600);
		this.setMinimumSize(new Dimension(600, 400));
		this.setMaximumSize(new Dimension(screenWidth, screenHeight - 30));
		this.setLocation((screenWidth - this.getWidth()) / 2, (screenHeight - this.getHeight() - 30) / 2);
		
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setResizable(true);
//		this.setUndecorated(true);  //去掉窗口的装饰
//		this.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
		//this.setUndecorated(true);
		//int size = this.getExtendedState();
		//size |= Frame.MAXIMIZED_BOTH;
       // this.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
		this.setVisible(true);
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				logoLabel.requestFocusInWindow();
			}
		});
	}
	
	/**
	 * <p>
	 * Title：构建元数据代码生成器菜单项
	 * </p>
	 * @return
	 */
	private JMenuItem buildMetadataGeneratorMenuItem() {
		JMenuItem metadataGeneratorMenuItem = new JMenuItem("代码生成器(D)");
		
		metadataGeneratorMenuItem.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "database_table.png"));
		metadataGeneratorMenuItem.setMnemonic('D');
		metadataGeneratorMenuItem.setAccelerator(KeyStroke.getKeyStroke('D', Event.CTRL_MASK, false));
		metadataGeneratorMenuItem.setActionCommand(MenuAdapter.METADATA_GENERATOR_COMMAND);
		metadataGeneratorMenuItem.addActionListener(this.menuAction);
		
		return metadataGeneratorMenuItem;
	}
	
	/**
	 * <p>
	 * Title：构建查询代码生成器菜单项
	 * </p>
	 * @return
	 */
	private JMenuItem buildQueryGeneratorMenuItem() {
		JMenuItem queryGeneratorMenuItem = new JMenuItem("查询设计器(Q)");
		
		queryGeneratorMenuItem.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "application_form.png"));
		queryGeneratorMenuItem.setMnemonic('Q');
		queryGeneratorMenuItem.setAccelerator(KeyStroke.getKeyStroke('Q', Event.CTRL_MASK, false));
		queryGeneratorMenuItem.setActionCommand(MenuAdapter.QUERY_GENERATOR_COMMAND);
		queryGeneratorMenuItem.addActionListener(this.menuAction);
		
		return queryGeneratorMenuItem;
	}
	
	/**
	 * <p>
	 * Title：构建全屏菜单项
	 * </p>
	 * @return
	 */
	private JMenuItem buildFullScreenMenuItem() {
		JMenuItem fullScreenMenuItem = new JMenuItem("全屏(F)");
		
		fullScreenMenuItem.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "arrow_out.png"));
		fullScreenMenuItem.setMnemonic('F');
		fullScreenMenuItem.setAccelerator(KeyStroke.getKeyStroke('F', Event.CTRL_MASK, false));
		fullScreenMenuItem.setActionCommand(MenuAdapter.FULL_SCREEN_COMMAND);
		fullScreenMenuItem.addActionListener(this.menuAction);
		
		return fullScreenMenuItem;
	}
	
	/**
	 * <p>
	 * Title：构建正常屏菜单项
	 * </p>
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 * @return
	 */
	private JMenuItem buildNormalScreenMenuItem() {
		JMenuItem normalScreenMenuItem = new JMenuItem("正常(N)");
		
		normalScreenMenuItem.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "arrow_in.png"));
		normalScreenMenuItem.setMnemonic('N');
		normalScreenMenuItem.setAccelerator(KeyStroke.getKeyStroke('N', Event.CTRL_MASK, false));
		normalScreenMenuItem.setActionCommand(MenuAdapter.NORMAL_SCREEN_COMMAND);
		normalScreenMenuItem.addActionListener(this.menuAction);
		
		return normalScreenMenuItem;
	}
	
	/**
	 * <p>
	 * Title：构建退出菜单项
	 * </p>
	 * @return
	 */
	private JMenuItem buildExitMenuItem() {
		JMenuItem exitMenuItem = new JMenuItem("退出(X)");
		
		exitMenuItem.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "cross.png"));
		exitMenuItem.setMnemonic('X');
		exitMenuItem.setAccelerator(KeyStroke.getKeyStroke('X', Event.CTRL_MASK, false));
		exitMenuItem.setActionCommand(MenuAdapter.EXIT_COMMAND);
		exitMenuItem.addActionListener(this.menuAction);
		
		return exitMenuItem;
	}
	
	/**
	 * <p>
	 * Title：构建菜单栏勾选菜单项
	 * </p>
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 * @return
	 */
	private JMenuItem buildMenuBarCheckBoxMenuItem() {
		JMenuItem menuBarCheckBoxMenuItem = new JCheckBoxMenuItem("菜单栏(M)", true);
		
		menuBarCheckBoxMenuItem.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "tick.png"));
		menuBarCheckBoxMenuItem.setMnemonic('M');
		menuBarCheckBoxMenuItem.setAccelerator(KeyStroke.getKeyStroke('M', Event.CTRL_MASK, false));
		menuBarCheckBoxMenuItem.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				if (e.getStateChange() == ItemEvent.SELECTED) {
					getJMenuBar().setVisible(true);
				} else {
					getJMenuBar().setVisible(false);
				}
			}
		});
		
		return menuBarCheckBoxMenuItem;
	}
	
	/**
	 * <p>
	 * Title：构建工具栏勾选菜单项
	 * </p>
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 * @return
	 */
	private JMenuItem buildToolBarCheckBoxMenuItem() {
		JCheckBoxMenuItem toolBarCheckBoxMenuItem = new JCheckBoxMenuItem("工具栏(T)", true);
		
		toolBarCheckBoxMenuItem.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "tick.png"));
		toolBarCheckBoxMenuItem.setMnemonic('T');
		toolBarCheckBoxMenuItem.setAccelerator(KeyStroke.getKeyStroke('T', Event.CTRL_MASK, false));
		toolBarCheckBoxMenuItem.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				if (e.getStateChange() == ItemEvent.SELECTED) {
					toolBar.setVisible(true);
				} else {
					toolBar.setVisible(false);
				}
			}
		});
		
		return toolBarCheckBoxMenuItem;
	}
	
	/**
	 * <p>
	 * Title：构建状态栏勾选菜单项
	 * </p>
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 * @return
	 */
	private JMenuItem buildStatusBarCheckBoxMenuItem() {
		JCheckBoxMenuItem statusBarCheckBoxMenuItem = new JCheckBoxMenuItem("状态栏(S)", true);
		
		statusBarCheckBoxMenuItem.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "tick.png"));
		statusBarCheckBoxMenuItem.setMnemonic('S');
		statusBarCheckBoxMenuItem.setAccelerator(KeyStroke.getKeyStroke('S', Event.CTRL_MASK, false));
		statusBarCheckBoxMenuItem.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				if (e.getStateChange() == ItemEvent.SELECTED) {
					statusBar.setVisible(true);
				} else {
					statusBar.setVisible(false);
				}
			}
		});
		
		return statusBarCheckBoxMenuItem;
	}
	
	/**
	 * <p>
	 * Title：构建窗口装饰样式勾选菜单项
	 * </p>
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 * @return
	 */
	private JMenuItem buildWindowDecorationStyleCheckBoxMenuItem() {
		JCheckBoxMenuItem windowDecorationStyleCheckBoxMenuItem = new JCheckBoxMenuItem("窗口装饰样式(W)", false);
		
		windowDecorationStyleCheckBoxMenuItem.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "tick.png"));
		windowDecorationStyleCheckBoxMenuItem.setMnemonic('W');
		windowDecorationStyleCheckBoxMenuItem.setAccelerator(KeyStroke.getKeyStroke('W', Event.CTRL_MASK, false));
		windowDecorationStyleCheckBoxMenuItem.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				if (e.getStateChange() == ItemEvent.SELECTED) {
					setUndecorated(true);  //去掉窗口的装饰
					//getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
					int size = getExtendedState();
					size |= Frame.MAXIMIZED_BOTH;
					setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
				} else {
					setUndecorated(false);  //恢复窗口的装饰
					//getRootPane().setWindowDecorationStyle(JRootPane.NONE);
				}
			}
		});
		
		return windowDecorationStyleCheckBoxMenuItem;
	}
	
	/**
	 * <p>
	 * Title：构建Look&Feel勾选菜单项
	 * </p>
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 * @return
	 */
	private JMenu buildLookAndFeelMenu() {
		final ButtonGroup lookAndFeelButtonGroup = new ButtonGroup();
		final JMenu lookAndFeelSettingMenu = new JMenu("Look&Feel(L)");
		
		lookAndFeelSettingMenu.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "color_wheel.png"));
		lookAndFeelSettingMenu.setMnemonic('L');
		final UIManager.LookAndFeelInfo[] lookAndFeelInfos = UIManager.getInstalledLookAndFeels();
		final String defaultLookAndFeelName = UIManager.getLookAndFeel().getName();
		final ActionListener lookAndFeelActionListener = new LookAndFeelAdapter(this);
		for (int i = 0; i < lookAndFeelInfos.length; i++) {
			final String oneLookAndFeelName = lookAndFeelInfos[i].getName();
			JRadioButtonMenuItem oneLookAndFeelMenuItem = new JRadioButtonMenuItem(oneLookAndFeelName);
			final String className = lookAndFeelInfos[i].getClassName();
			if(defaultLookAndFeelName.equals(oneLookAndFeelName)) {
				oneLookAndFeelMenuItem.setSelected(true);
			}
			oneLookAndFeelMenuItem.setActionCommand(className);
			oneLookAndFeelMenuItem.addActionListener(lookAndFeelActionListener);
			lookAndFeelButtonGroup.add(oneLookAndFeelMenuItem);
			lookAndFeelSettingMenu.add(oneLookAndFeelMenuItem);
		}
		
		return lookAndFeelSettingMenu;
	}
	
	/**
	 * <p>
	 * Title：构建个人喜好设置菜单项
	 * </p>
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 * @return
	 */
	private JMenuItem buildPreferencesMenuItem() {
		JMenuItem preferencesMenuItem = new JMenuItem("系统设置(P)...");
		
		preferencesMenuItem.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "cog.png"));
		preferencesMenuItem.setMnemonic('P');
		preferencesMenuItem.setAccelerator(KeyStroke.getKeyStroke('P', Event.CTRL_MASK, false));
		preferencesMenuItem.setActionCommand(MenuAdapter.PREFERENCES_COMMAND);
		preferencesMenuItem.addActionListener(this.menuAction);
		
		return preferencesMenuItem;
	}
	
	/**
	 * <p>
	 * Title：构建帮助菜单项
	 * </p>
	 * @return
	 */
	private JMenuItem buildHelpMenuItem() {
		JMenuItem helpMenuItem = new JMenuItem("帮助主题(H)");
		
		helpMenuItem.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "help.png"));
		helpMenuItem.setMnemonic('H');
		helpMenuItem.setAccelerator(KeyStroke.getKeyStroke('H', Event.CTRL_MASK, false));
		helpMenuItem.setActionCommand(MenuAdapter.HELP_COMMAND);
		helpMenuItem.addActionListener(this.menuAction);
		
		return helpMenuItem;
	}
	
	/**
	 * <p>
	 * Title：构建软件更新菜单项
	 * </p>
	 * @return
	 */
	private JMenuItem buildLinkMenuItem() {
		JMenuItem linkMenuItem = new JMenuItem("链接(L)");
		
		linkMenuItem.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "link.png"));
		linkMenuItem.setMnemonic('L');
		linkMenuItem.setAccelerator(KeyStroke.getKeyStroke('L', Event.CTRL_MASK, false));
		linkMenuItem.setActionCommand(MenuAdapter.LINK_COMMAND);
		linkMenuItem.addActionListener(this.menuAction);
		
		return linkMenuItem;
	}
	
	/**
	 * <p>
	 * Title：构建软件更新菜单项
	 * </p>
	 * @return
	 */
	private JMenuItem buildUpdateMenuItem() {
		JMenuItem updateMenuItem = new JMenuItem("软件更新(U)");
		
		updateMenuItem.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "world_connect.png"));
		updateMenuItem.setMnemonic('U');
		updateMenuItem.setAccelerator(KeyStroke.getKeyStroke('U', Event.CTRL_MASK, false));
		updateMenuItem.setActionCommand(MenuAdapter.UPDATE_COMMAND);
		updateMenuItem.addActionListener(this.menuAction);
		
		return updateMenuItem;
	}
	
	/**
	 * <p>
	 * Title：构建关于菜单项
	 * </p>
	 * @return
	 */
	private JMenuItem buildAboutMenuItem() {
		JMenuItem aboutMenuItem = new JMenuItem("关于XGenerator(A)");
		
		aboutMenuItem.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "application.png"));
		aboutMenuItem.setMnemonic('A');
		aboutMenuItem.setAccelerator(KeyStroke.getKeyStroke('A', Event.CTRL_MASK, false));
		aboutMenuItem.setActionCommand(MenuAdapter.ABOUT_COMMAND);
		aboutMenuItem.addActionListener(this.menuAction);
		
		return aboutMenuItem;
	}
	
	/**
	 * <p>
	 * Title：构建代码生成器菜单
	 * </p>
	 * @return
	 */
	private JMenu buildGeneratorsMenu() {
		JMenu generatorsMenu = new JMenu("代码生成器(G)");
		generatorsMenu.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "app.gif"));
		generatorsMenu.setMnemonic('G');

		generatorsMenu.add(buildMetadataGeneratorMenuItem());
		generatorsMenu.add(buildQueryGeneratorMenuItem());
		generatorsMenu.addSeparator();
		generatorsMenu.add(buildExitMenuItem());
		
		return generatorsMenu;
	}
	
	/**
	 * <p>
	 * Title：构建工具菜单
	 * </p>
	 * @return
	 */
	private JMenu buildToolMenu() {
		JMenu toolMenu = new JMenu("工具(T)");
		toolMenu.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "wrench.png"));
		toolMenu.setMnemonic('T');
		
		toolMenu.add(buildPreferencesMenuItem());
		
		return toolMenu;
	}
	
	/**
	 * <p>
	 * Title：构建视图菜单
	 * </p>
	 * @return
	 */
	private JMenu buildViewMenu() {
		JMenu viewMenu = new JMenu("视图(V)");
		viewMenu.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "eye.png"));
		viewMenu.setMnemonic('V');
		
		viewMenu.add(buildMenuBarCheckBoxMenuItem());
		viewMenu.add(buildToolBarCheckBoxMenuItem());
		viewMenu.add(buildStatusBarCheckBoxMenuItem());
		viewMenu.add(buildWindowDecorationStyleCheckBoxMenuItem());
		viewMenu.addSeparator();
		viewMenu.add(buildFullScreenMenuItem());
		viewMenu.add(buildNormalScreenMenuItem());
		viewMenu.addSeparator();
		viewMenu.add(buildLookAndFeelMenu());
		
		return viewMenu;
	}
	
	/**
	 * <p>
	 * Title：构建帮助菜单
	 * </p>
	 * @return
	 */
	private JMenu buildHelpMenu() {
		JMenu helpMenu = new JMenu("帮助(H)");
		helpMenu.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "info.png"));
		helpMenu.setMnemonic('H');
		
		helpMenu.add(buildHelpMenuItem());
		helpMenu.add(buildLinkMenuItem());
		helpMenu.addSeparator();
		helpMenu.add(buildUpdateMenuItem());
		helpMenu.addSeparator();
		helpMenu.add(buildAboutMenuItem());
		
		return helpMenu;
	}
	
	/**
	 * <p>
	 * Title：构造菜单栏
	 * </p>
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 * @return
	 */
	private JMenuBar buildJMenuBar() {
		JMenuBar menuBar = new JMenuBar();

		menuBar.add(buildGeneratorsMenu());
		menuBar.add(buildToolMenu());
		menuBar.add(buildViewMenu());
		menuBar.add(buildHelpMenu());
		
		return menuBar;
	}
	
	/**
	 * <p>
	 * Title：构建右键菜单
	 * </p>
	 * @return
	 */
	private JPopupMenu buildPopupMenu() {
		JPopupMenu popupMenu = new JPopupMenu();
		
		popupMenu.add(buildMenuBarCheckBoxMenuItem());
		popupMenu.addSeparator();
		popupMenu.add(buildFullScreenMenuItem());
		popupMenu.add(buildNormalScreenMenuItem());
		popupMenu.addSeparator();
		popupMenu.add(buildExitMenuItem());
		
		return popupMenu;
	}
	
	/**
	 * <p>
	 * Title：构造工具栏
	 * </p>
	 * 
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 * @return
	 */
	private JToolBar buildToolBar() {
		JToolBar toolBar = new JToolBar("工具栏");
		toolBar.setFloatable(false);
//		toolBar.setBackground(java.awt.Color.GREEN);

		final ButtonGroup buttonGroup = new ButtonGroup();
		JToggleButton homeBtn = new JToggleButton(IconUtils.createImageIcon(ICON_CLASS_PATH + "home.png"));
		JToggleButton generatorBtn = new JToggleButton(IconUtils.createImageIcon(ICON_CLASS_PATH + "jarbundler.png"));
		JToggleButton designerBtn = new JToggleButton(IconUtils.createImageIcon(ICON_CLASS_PATH + "design.png"));
		JToggleButton templateBtn = new JToggleButton(IconUtils.createImageIcon(ICON_CLASS_PATH + "template.png"));
		JToggleButton viewBtn = new JToggleButton(IconUtils.createImageIcon(ICON_CLASS_PATH + "Cube.png"));
		this.logoLabel = new JLabel(IconUtils.createImageIcon(IMAGE_CLASS_PATH + "xgenerator.png"));
		this.logoLabel.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				buttonGroup.clearSelection();
				logoLabel.requestFocusInWindow();
			}
		});
		
		homeBtn.setText("首页");
		homeBtn.setToolTipText("首页");
		homeBtn.setHorizontalTextPosition(JButton.CENTER);
		homeBtn.setHorizontalAlignment(JButton.CENTER);
		homeBtn.setVerticalTextPosition(JButton.BOTTOM);
		
		generatorBtn.setText("代码生成器");
		generatorBtn.setToolTipText("元数据代码生成器");
		generatorBtn.setHorizontalTextPosition(JButton.CENTER);
		generatorBtn.setHorizontalAlignment(JButton.CENTER);
		generatorBtn.setVerticalTextPosition(JButton.BOTTOM);
		generatorBtn.setVerticalTextPosition(JButton.BOTTOM);
		generatorBtn.setActionCommand(MenuAdapter.METADATA_GENERATOR_COMMAND);
		generatorBtn.addActionListener(this.menuAction);

		designerBtn.setText("查询设计器");
		designerBtn.setToolTipText("查询设计器");
		designerBtn.setHorizontalTextPosition(JButton.CENTER);
		designerBtn.setHorizontalAlignment(JButton.CENTER);
		designerBtn.setVerticalTextPosition(JButton.BOTTOM);
		
		templateBtn.setText("模板管理");
		templateBtn.setToolTipText("模板管理");
		templateBtn.setHorizontalTextPosition(JButton.CENTER);
		templateBtn.setHorizontalAlignment(JButton.CENTER);
		templateBtn.setVerticalTextPosition(JButton.BOTTOM);
		
		viewBtn.setText("布局排版");
		viewBtn.setToolTipText("界面布局排版");
		viewBtn.setHorizontalTextPosition(JButton.CENTER);
		viewBtn.setHorizontalAlignment(JButton.CENTER);
		viewBtn.setVerticalTextPosition(JButton.BOTTOM);

		buttonGroup.add(homeBtn);
		buttonGroup.add(generatorBtn);
		buttonGroup.add(designerBtn);
		buttonGroup.add(templateBtn);
		buttonGroup.add(viewBtn);

		toolBar.add(homeBtn);
		toolBar.addSeparator();
		toolBar.add(generatorBtn);
		toolBar.add(designerBtn);
		toolBar.addSeparator();
		toolBar.add(templateBtn);
		toolBar.add(viewBtn);
		toolBar.add(logoLabel);
		
		toolBar.setComponentPopupMenu(buildPopupMenu());
		
		return toolBar;
	}
	
	/**
	 * <p>
	 * Title：构造中间面板
	 * </p>
	 * 
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 * @return
	 */
	private JPanel buildCenterPane() {
		JPanel centerPanel = new JPanel();
//		centerPanel.setLayout(new BorderLayout());
		centerPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
		
		centerPanel.setBackground(Color.WHITE);
		centerPanel.add(new BackgroundImageLabel(IMAGE_CLASS_PATH + "1.jpg"));
		
		return centerPanel;
		
		/*
		JPanel backgroundImagePanel = new BackgroundImagePanel(IMAGE_CLASS_PATH + "8.jpg", Color.WHITE);
		return backgroundImagePanel;
		*/
	}
	
	/**
	 * <p>
	 * Title：构造南部面板
	 * </p>
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 * @return
	 */
	private JPanel buildSouthPane() {
		JPanel southPanel = new JPanel();
		southPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
		
		southPanel.add(new JLabel("主程序版本：1.0.0.0"));
		southPanel.add(new JLabel("   "));
		JLabel checkUpdateLabel = new JLabel();
		checkUpdateLabel.setText("<html><a href='http://www.google.cn'target='_blank'>检查更新</a></html>");
		
		checkUpdateLabel.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				try {
					HttpClient httpClient = new HttpClient();
					String requestUrl = "http://liss.iteye.com/";
					String responseEncoding = "UTF-8";
					//System.out.println(httpClient.doGet(requestUrl, responseEncoding));
					if(true) {
						JOptionPane.showMessageDialog(e.getComponent().getParent().getParent(), "恭喜！\n你的XGenerator已经是最新版本。", "XGenerator在线升级", JOptionPane.INFORMATION_MESSAGE);
					} else {
						JOptionPane.showMessageDialog(e.getComponent().getParent().getParent(), "你将升级到2.0版本，新增功能和优化点如下：", "XGenerator在线升级", JOptionPane.INFORMATION_MESSAGE);
					}
				} catch (Exception ex) {
					JOptionPane.showMessageDialog(e.getComponent().getParent().getParent(), ex.getMessage(), "XGenerator在线升级", JOptionPane.INFORMATION_MESSAGE);
				}
			}
		});
		southPanel.add(checkUpdateLabel);
		
		return southPanel;
	}
	
	/**
	 * <p>
	 * Title：构造ContentPane
	 * </p>
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 * @return
	 */
	private JPanel buildContentPane() {
		JPanel contentPanel = new JPanel();
		contentPanel.setLayout(new BorderLayout());

		this.toolBar = buildToolBar();
		this.homePanel = buildCenterPane();
		this.statusBar = buildSouthPane();

		contentPanel.add(this.toolBar, BorderLayout.NORTH);
		contentPanel.add(this.homePanel, BorderLayout.CENTER);
		contentPanel.add(this.statusBar, BorderLayout.SOUTH);
		
		/*
		 * 添加右键菜单
		 */
		contentPanel.setComponentPopupMenu(buildPopupMenu());
		
		/*
		 * 添加鼠标双击事件
		 */
		contentPanel.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if(MouseEvent.BUTTON2 == e.getClickCount()) {
					if(isFullScreen) {
						isFullScreen = false;
						setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
					} else {
						isFullScreen = true;
						setExtendedState(java.awt.Frame.NORMAL);
					}
				}
			}
		});

		return contentPanel;
	}

	public boolean isFullScreen() {
		return isFullScreen;
	}

	public void setFullScreen(boolean isFullScreen) {
		this.isFullScreen = isFullScreen;
	}
	
}
